package com.mz.mattress.client.timer;

import com.mz.mattress.api.entity.OrderUseTimes;
import com.mz.mattress.api.enums.DeviceOptionEnum;
import com.mz.mattress.api.mattress.OpenClientApi;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DeviceStartTask implements Runnable {

    private OpenClientApi openClientApi;

    private OrderUseTimes times;

    public DeviceStartTask(OpenClientApi openClientApi, OrderUseTimes times) {
        this.openClientApi = openClientApi;
        this.times = times;
    }

    @Override
    public void run() {

        try {

            if (times.getStart() == null) {
                openClientApi.sendOptions(times.getDeviceCode(), times.getProductKey(), DeviceOptionEnum.minute, 60);
            }

//            openClientApi.sendOptions(times.getDeviceCode(), times.getProductKey(), DeviceOptionEnum.temper, 45);
//            openClientApi.sendOptions(times.getDeviceCode(), times.getProductKey(), DeviceOptionEnum.volume, 3);
//            openClientApi.sendOptions(times.getDeviceCode(), times.getProductKey(), DeviceOptionEnum.strength, 3);

            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            openClientApi.sendOptions(times.getDeviceCode(), times.getProductKey(), DeviceOptionEnum.start, null);

            if (times.getMode() != 1) {
                openClientApi.sendOptions(times.getDeviceCode(), times.getProductKey(), DeviceOptionEnum.mode, times.getMode());
            }

        } catch (Exception e) {
            log.error("DeviceStartTask_error", e);
        }

    }


}
